package com.ms.seguridad.service.impl;


import com.ms.seguridad.UserInfo;
import com.ms.seguridad.service.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * User: AW
 * Date: 24/02/13
 */
@Service
public class SecurityServiceImpl implements SecurityService {

    private static final String LOGIN_SUCCESSFULL = "OK";

    protected final Logger LOG = LoggerFactory.getLogger(this.getClass());



    public UserInfo login(String user, String password, String ipAddress,int applicationCode) {

        LOG.info("User:"+user +" logged succesfully");
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new SimpleGrantedAuthority("ROLE_DPWC_USER"));
        authorities.add(new SimpleGrantedAuthority("ROLE_fnTeApuesto"));
        UserInfo usuario = new UserInfo("admin","1234",true,true,true,true,authorities);
        return usuario;
    }

    /*public List<ModuleBean> getModuleListFrom(List<ModuleType> modulesType) {
        List<ModuleBean> moduleList = new ArrayList<ModuleBean>();
        for (ModuleType moduleType : modulesType) {
            ModuleBean moduleBean = new ModuleBean();
            moduleBean.setModuleName(moduleType.getModuleName());
            List<ModuleType> subModTypes = moduleType.getModulesType();
            if (subModTypes != null && subModTypes.size() > 0) {
                List<ModuleBean> subModuleList = new ArrayList<ModuleBean>();
                for (ModuleType subModType : subModTypes) {
                    if (!subModType.isEnabled()) {
                        continue;
                    }
                    ModuleBean subModuleBean = new ModuleBean();
                    subModuleBean.setModuleName(subModType.getModuleName());
                    subModuleBean.setModuleUrl(subModType.getModuleUrl());
                    subModuleList.add(subModuleBean);
                }
                if (subModuleList.size() > 0) {
                    moduleBean.setModuleList(subModuleList);
                    moduleList.add(moduleBean);
                }
            }
        }
        return moduleList;
    }*/

}
